package cn.iocoder.yudao.module.voice.cc.mq;

import cn.iocoder.yudao.module.voice.cc.mq.message.RocketMQMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;

/**
 *
 * @author 芋道源码
 */
@Slf4j
public class RocketMQVoiceMessageSender {

    private final RocketMQTemplate rocketMQTemplate;

    private final String topic;

    public RocketMQVoiceMessageSender(RocketMQTemplate rocketMQTemplate,
                                      String topic) {
        this.rocketMQTemplate = rocketMQTemplate;
        this.topic = topic;
    }
    public void send(String messageContent) {
        sendRocketMQMessage( messageContent);
    }

    /**
     * 通过 RocketMQ 广播消息
     * @param sessionId Session 编号
     * @param messageContent 消息内容
     */
    private void sendRocketMQMessage(String messageContent) {
        RocketMQMessage mqMessage = new RocketMQMessage()
         .setMessage(messageContent);
        rocketMQTemplate.syncSend(topic, mqMessage,20000);
    }

}
